﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace TuyennvLibrary.SqlClient
{
    public class BaseClass
    {
        public void CopyTo(Object target)
        {
            Type sourceType = this.GetType();
            Type destinationType = target.GetType();

            foreach (PropertyInfo sourceProperty in sourceType.GetProperties())
            {
                PropertyInfo destinationProperty = destinationType.GetProperty(sourceProperty.Name);
                if (destinationProperty != null)
                {
                    destinationProperty.SetValue(target, sourceProperty.GetValue(this, null), null);
                }
            }
        }
        public object CopyTo(Type destinationType)
        {
            Type sourceType = this.GetType();
            //= target.GetType();
            object target = Activator.CreateInstance(destinationType);
            foreach (PropertyInfo sourceProperty in sourceType.GetProperties())
            {
                PropertyInfo destinationProperty = destinationType.GetProperty(sourceProperty.Name);
                if (destinationProperty != null)
                {
                    destinationProperty.SetValue(target, sourceProperty.GetValue(this, null), null);
                }
            }
            return target;
        }
    }
}
